package com.sunjq.personalblog.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.sunjq.personalblog.dao.ArticleDAO;
import com.sunjq.personalblog.domain.Article;

public class ArticleDAOImpl implements ArticleDAO {
	
	
	private HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	@Override
	public List<Article> findAll() {
		List<Article> articles = (List<Article>) this.hibernateTemplate.find("from Article a");
		return articles;
	}

	@Override
	public Article findByID(Integer id) {
		return this.hibernateTemplate.get(Article.class, id);
	}

	@Override
	public void persist(Article a) {
		this.hibernateTemplate.persist(a);

	}

}
